<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="../common/meta.jsp"%>
<%@ include file="../common/taglibs.jsp"%>
<link rel="stylesheet" type="text/css"
	href="<%=request.getContextPath()%>/easyui/themes/myself/easyui.css" />
<link rel="stylesheet" type="text/css"
	href="<%=request.getContextPath()%>/easyui/themes/icon.css" />
<script type="text/javascript"
	src='<%=request.getContextPath()%>/dwr/engine.js'></script>
<script type="text/javascript"
	src='<%=request.getContextPath()%>/dwr/util.js'></script>
<script type="text/javascript"
	src='<%=request.getContextPath()%>/dwr/interface/baseVerifyService.js'></script>
<style>
.btn {
	BORDER-RIGHT: 0px;
	BORDER-TOP: 0px;
	BACKGROUND: url(<%=request.getContextPath()%>/images/bg_rectbtn.png) -2px -2px repeat-x;
	OVERFLOW: hidden;
	BORDER: solid 1px #83858C;
}
</style>
<script type="text/javascript">
	function addSubRole() {
	    var bform = document.getElementById("ctRoleForm");
	    bform.action = "edit.action?operate=insertSub";
	    bform.target = "_self";
	    bform.submit();
	}
	function deleteRole(roleId) {
	    baseVerifyService.isRoleRefByStaff(roleId, {callback:function(data) {
	        showVerify(data, roleId);
	    }});
	}
	function saveRole() {
		parent.$.messager.progress();
		$("#ctRoleForm").form("submit",{
			url: "save.action?operate=${operate}",			
			onSubmit: function() {
			   var roleNameObj = this['roleName'];
			   if (roleNameObj.value == "") {
			     parent.$.messager.progress('close');
 			     alert("请输入角色名称！");
			     roleNameObj.focus();
			     return false;
			   }
			},
			success: function(data) {
				parent.$.messager.progress('close');
				alert('保存成功!');
				var node = parent.$("#roleTree").tree("getSelected");
				if('${operate}' == 'insertSub') {
					parent.$("#roleTree").tree('reload',node.target);
					parent.$("#roleTree").tree('select',node.target);
				} else if('${operate}' == 'editView') {
					var parentNode = parent.$("#roleTree").tree('getParent',node.target);
					parent.$("#roleTree").tree('reload',parentNode.target);
					parent.$("#roleTree").tree('select',parentNode.target);
				}
			}
		});
	}
	function showVerify(data, roleId) {
		if (data != null && data != "") {
	        alert("此角色或者其子角色已经被用户"+data+"关联，不允许删除！");
	        return false;
	    } else if (confirm("确认删除此角色？")) {
			$("#ctRoleForm").form("submit",{
				url: "delete.action?roleId=" + roleId,		
				success: function(data) {
					parent.$.messager.progress('close');
					alert('删除成功!');
					var node = parent.$("#roleTree").tree("getSelected");
					var parentNode = parent.$("#roleTree").tree('getParent',node.target);
					parent.$("#roleTree").tree('reload',parentNode.target);
					parent.$("#roleTree").tree('select',parentNode.target);
				}
			});
		}
	}
</script>
<style>
* {
	margin: 0;
	padding: 0;
	font-size: 12px;
}
</style>
</head>
<body>
	<div class="easyui-layout" data-options="fit:true">
	<form id="ctRoleForm" method="post">
		<input type="hidden" id="roleId" name="role.roleId" value="${role.roleId}"/>
		<input type="hidden" id="parentId" name="role.parentId" value="${role.parentId}"/>
			<div data-options="region:'center', border:false">
				<div class="easyui-layout" data-options="fit:true">
					<div data-options="region:'center', border:false"
						style="border: 1px solid #ccc; padding: 5px;">
						<table border="0" align="center" cellpadding="3" cellspacing="1"
							class="tb_input">
							<tr>
								<td colspan="2" height="30px"><s:if
										test="#request.operate eq 'editView'">
										<input type="button" value="创建子角色" class="btn"
											onclick="addSubRole()" />&nbsp;
										<input type="button" value="删除此角色"
											class="btn" onclick="deleteRole('${role.roleId}')" />
									</s:if>
									<s:else>创建角色</s:else>
								</td>
							</tr>
							<tr>
								<td class="td_title" nowrap="nowrap" width="100px">角色名称<font
									color="#FF0000">*</font></td>
								<td><input type="text" id="roleName" name="role.roleName"
									value="${role.roleName}" style="WIDTH: 250px" /></td>
							</tr>
							<tr>
								<td class="td_title" nowrap="nowrap" width="100px">角色说明</td>
								<td><textarea id="memo" name="role.memo" rows="3" cols="45">${role.memo}</textarea>
								</td>
							</tr>
						</table>
						<br />
						<table border="0" align="center" cellpadding="0" cellspacing="0">
							<tr>
								<td align="center"><input type="button" value="保存"
									class="btn" onclick="saveRole()" /></td>
							</tr>
						</table>
					</div>
				</div>
			</div>
		</form>
	</div>
</body>
</html>